using System;
using System.Drawing;

namespace OpenComposite.Base.Designer
{
	public class Button : Symbol
	{
		#region Initialization
		public Button()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			//this.Name = "button" + GetCount(typeof(Button));
			this.Text = "+";
			this.MouseOverColor = Color.Azure;

			_colorBackSave = this.BackColor;

			this.Size = new Size(15, 15);
			this.MinimumSize = new Size(5, 5);

			this.NameTextBox.ReadOnly = true;
			this.NameTextBox.BorderVisibilityStyle = BorderVisibilityStyle.Never;
			this.NameTextBox.MouseClick += new System.Windows.Forms.MouseEventHandler(NameTextBox_MouseClick);

			this.Border = BorderType.RoundedRectangle;
			this.BorderWidth = 1;
			this.BorderFixedRoundedBorderDiameter = 2;

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		#region Events
		public event EventHandler Click = null;
		#endregion

		#region Properties
		public Color MouseOverColor
		{
			get { return _colorMouseOver; }
			set {
				_colorMouseOver = value;
				this._colorBackSave = this.BackColor;
			}
		}
		#endregion

		#region Override

		#region Properties
		public override bool CanFocused
		{
			get
			{
				return true;
			}
		}
		public override bool CanMove
		{
			get
			{
				return false;
			}
		}
		public override bool CanResize
		{
			get
			{
				return false;
			}
		}
		public override bool CanSelect
		{
			get
			{
				return false;
			}
		}
		public override bool IsContainer
		{
			get
			{
				return false;
			}
		}
		public override bool NoClip
		{
			get
			{
				return false;
			}
		}
		public override bool UseGrid
		{
			get
			{
				return false;
			}
		}
		#endregion

		public override void PaintBackground(System.Windows.Forms.PaintEventArgs pe)
		{
			base.PaintBackground(pe);
		}
		public override void Paint(System.Windows.Forms.PaintEventArgs pe)
		{
			base.Paint(pe);
		}
		public override void Dispose()
		{
			base.Dispose();
			dispose(_colorBackSave);
			dispose(_colorMouseOver);
		}
		#endregion

		#endregion

		#region Protected Members

		#region Methods
		public virtual void OnClick(EventArgs e)
		{
			EventHandler tmp = this.Click;
			if ( tmp != null )
				tmp(this, e);
		}
		#endregion

		#region Override

		protected override void OnMouseEnter(EventArgs e)
		{
			if ( this.BackColor != this.MouseOverColor ) {
				this.BeginUpdate();
				_colorBackSave = this.BackColor;
				this.BackColor = this.MouseOverColor;
				base.OnMouseEnter(e);
				this.EndUpdate();
			}
		}
		protected override void OnMouseLeave(EventArgs e)
		{
			if ( this.BackColor != _colorBackSave ) {
				this.BeginUpdate();
				this.BackColor = _colorBackSave;
				base.OnMouseLeave(e);
				this.EndUpdate();
			}
		}
		protected override void OnMouseClick(System.Windows.Forms.MouseEventArgs e)
		{
			OnClick(new EventArgs());
			base.OnMouseClick(e);
		}

		protected override Rectangle CalculateClientArea()
		{
			Rectangle rc = this.Bounds;
			rc.Inflate(-1, -1);
			return rc;
		}
		#endregion

		#endregion

		#region Private Members

		private Color _colorMouseOver;
		private Color _colorBackSave;

		private new TextBox NameTextBox
		{
			get { return base.NameTextBox; }
		}

		private void NameTextBox_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			OnClick(new EventArgs());
		}
		#endregion
	}
}

